(function($) {

  var app = $.sammy('#content', function() {
    this.before(function(callback) {
      var context = this;
    });

    this.get('#/', function(context) {
        $('#login_submit').button();
    });
    
    this.post('#/', function(context) {
        $.ajax({
            url: 'index.php?method=login',
            type: "get",
            dataType: 'json',
            data: 'username=' + this.params['username'] + '&password=' + this.params['password'],
            async: false,
            success: function(response) {
                if(response.sStatus == "action_successfull")
                    context.redirect("userData.php");
                else {
                    $('#loginStatus').text(response.sReason).addClass("ui-state-error");
                }
            }
        });
    });
  });

  $(function() {
    app.run('#/');
  });

})(jQuery);
